/*
 * @(#)WorkflowProgress.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.workflow.bean;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.Utility;
import com.dcivision.framework.bean.AbstractBaseObject;

/**
 * WorkflowProgress.java
 * 
 * This class is the serializable bean reflecting business logic uses.
 * It represents a workflow progress (workflow task) object. 
 * 
 * @author Rollo Chan
 * @company DCIVision Limited
 * @creation date 05/09/2003
 * @version $Revision: 1.38 $
 * @see com.dcivision.workflow.bean.WorkflowStep
 * @see com.dcivision.workflow.bean.MtmWfProgressWfProgress
 */
public class WorkflowProgress extends AbstractBaseObject {
  
  public static final String REVISION = "$Revision: 1.38 $";
  
  static final long serialVersionUID = -4123372596614434960L;
  
  /** Indicates the task is submitted */
  public static final String STATUS_SUBMIT = "S";
  /** Indicates the task is approved */
  public static final String STATUS_APPROVE = "A";
  /** Indicates the task is approved */
  public static final String STATUS_REJECT = "R";
  /** Indicates the task is selected yes */
  public static final String STATUS_YES = "T";
  /** Indicates the task is selected no */
  public static final String STATUS_NO = "F";
  /** Indicates the task is still pending */
  public static final String STATUS_PENDING = "P";
  /** Indicates the task is completed */
  public static final String STATUS_GENERAL_ACCOMPLISHMENT = "G";
  /** Indicates the task is overdued */
  public static final String STATUS_NO_RESPONSE = "N";
  /** Indicates the task is being cancelled */
  public static final String STATUS_CANCEL = "C";
  /** Indicates the task is checked out */
  public static final String STATUS_IN_PROGRESS = "I";
  /** Indicates the task is in post progress state (assign next step owners) */
  public static final String STATUS_POST_PROGRESS = "O";
  /** Indicates the task is rolled back */
  public static final String STATUS_ROLLBACK = "B";
  /** Indicates the task is revoked */
  public static final String STATUS_REVOKE = "V";
  /** Indicates the task is skipped */
  public static final String STATUS_SKIP = "K";
  /** Indicates the task is locked */
  public static final String STATUS_LOCK = "L";
  
  public static final String SEARCH_ARRIVAL_DATE = "ARRIVAL_DATE"; //search field in ListWorkflowTask.jsp
  public static final String SEARCH_DUE_DATE = "DUE_DATE";   //search field in ListWorkflowTask.jsp
  
  /** Indicates the task is routed to default due to fail of evaluation of form equation */
  public static final String ROUTED_TO_DEFAULT = "D";
  /** Indicates the task is routed to default due to error of form equation */
  public static final String FORM_EQUATION_ERROR = "E";
  
  private Integer workflowStepID = null;
  private Integer trackID = null;
  private String cancelFlag = null;
  private String completeFlag = null;
  private Integer seqNo = null;
  private String status = null;
  private Timestamp dueDate = null;
  private Timestamp nextStepDueDate = null;
  private String progressPriority = null;
  private String nextStepAllowAssignDueDate = null;
  private String nextStepDueDates = null;
  
  private String userDef1 = null;
  private String userDef2 = null;
  private String userDef3 = null;
  private String userDef4 = null;
  private String userDef5 = null;
  
  private WorkflowStep workflowStepSource = null;
  
  private String workflowCode = null;         // Presentation ONLY
  private String workflowVersion = null;      // Presentation ONLY
  private String workflowDescription = null;  // Presentation ONLY
  private String workflowCategory = null;     // Presentation ONLY
  private Integer workflowCategoryID = null;  // Presentation ONLY
  private Integer workflowRecordID = null;    // Presentation ONLY
  private Integer stepSeq = null;             // Presentation ONLY
  private String stepName = null;             // Presentation ONLY
  private String allowAssignDueDate = null;   // Presentation ONLY
  private String actionType = null;           // Presentation ONLY
  private String stepDescription = null;      // Presentation ONLY
  private String priority = null;             // Presentation ONLY
  private Timestamp onNoResponseAfter = null; // Presentation ONLY
  private Integer onNoResponseFor = null;     // Presentation ONLY
  private Timestamp startDate = null; // Presentation ONLY
  private Timestamp endDate = null; // Presentation ONLY
  private String submitter = null; // Presentation ONLY
  private String allowStop = GlobalConstant.FALSE;
  private String oldStatus = null;
  private String postProgress = null;
  private Integer viewUserRecordID = null;
  private Integer delegateUserRecordID = null;
  private String stageName = null;
  
  private String priorityRuleListValue = null;
  private boolean isAssignPriorityRuleNextStep = false;
  
  private String childCreateType = "N";
  
  private List pickUpUserName = null;
  
  /**
   * @return Returns the childCreateType.
   */
  public String getChildCreateType() {
    return childCreateType;
  }
  /**
   * @param childCreateType The childCreateType to set.
   */
  public void setChildCreateType(String childCreateType) {
    this.childCreateType = childCreateType;
  }
  /**
   * @return Returns the postProgress.
   */
  public String getPostProgress() {
    return postProgress;
  }
  /**
   * @param postProgress The postProgress to set.
   */
  public void setPostProgress(String postProgress) {
    this.postProgress = postProgress;
  }
  private List userActorList = new ArrayList();
  
  public WorkflowProgress() {
    super();
  }
  
  /**
   * @return Returns the viewUserRecordID.
   */
  public Integer getViewUserRecordID() {
    return viewUserRecordID ;
  }
  /**
   * @param viewUserRecordID The viewUserRecordID to set.
   */
  public void setViewUserRecordID(Integer viewUserRecordID) {
    this.viewUserRecordID  = viewUserRecordID;
  }
  
  /**
   * @return Returns the delegateUserRecordID.
   */
  public Integer getDelegateUserRecordID() {
    return delegateUserRecordID ;
  }
  /**
   * @param delegateUserRecordID The delegateUserRecordID to set.
   */
  public void setDelegateUserRecordID(Integer delegateUserRecordID) {
    this.delegateUserRecordID  = delegateUserRecordID;
  }
  /**
   * @return Returns the workflowStepID.
   */
  public Integer getWorkflowStepID() {
    return(this.workflowStepID);
  }
  /**
   * @param workflowStepID The workflowStepID to set.
   */
  public void setWorkflowStepID(Integer workflowStepID) {
    this.workflowStepID = workflowStepID;
  }
  /**
   * @return Returns the trackID.
   */
  public Integer getTrackID() {
    return(this.trackID);
  }
  /**
   * @param trackID The trackID to set.
   */
  public void setTrackID(Integer trackID) {
    this.trackID = trackID;
  }
  /**
   * @return Returns the cancelFlag.
   */
  public String getCancelFlag() {
    return(this.cancelFlag);
  }
  /**
   * @param cancelFlag The cancelFlag to set.
   */
  public void setCancelFlag(String cancelFlag) {
    this.cancelFlag = cancelFlag;
  }
  /**
   * @return Returns the completeFlag.
   */
  public String getCompleteFlag() {
    return(this.completeFlag);
  }
  /**
   * @param completeFlag The completeFlag to set.
   */
  public void setCompleteFlag(String completeFlag) {
    this.completeFlag = completeFlag;
  }
  /**
   * @return Returns the seqNo.
   */
  public Integer getSeqNo() {
    return(this.seqNo);
  }
  /**
   * @param seqNo The seqNo to set.
   */
  public void setSeqNo(Integer seqNo) {
    this.seqNo = seqNo;
  }
  /**
   * @return Returns the status.
   */
  public String getStatus() {
    return(this.status);
  }
  /**
   * @param status The status to set.
   */
  public void setStatus(String status) {
    this.status = status;
  }
  /**
   * @return Returns the userDef1.
   */
  public String getUserDef1() {
    return(this.userDef1);
  }
  /**
   * @param userDef1 The userDef1 to set.
   */
  public void setUserDef1(String userDef1) {
    this.userDef1 = userDef1;
  }
  /**
   * @return Returns the userDef2.
   */
  public String getUserDef2() {
    return(this.userDef2);
  }
  /**
   * @param userDef2 The userDef2 to set.
   */
  public void setUserDef2(String userDef2) {
    this.userDef2 = userDef2;
  }
  /**
   * @return Returns the userDef3.
   */
  public String getUserDef3() {
    return(this.userDef3);
  }
  /**
   * @param userDef3 The userDef3 to set.
   */
  public void setUserDef3(String userDef3) {
    this.userDef3 = userDef3;
  }
  /**
   * @return Returns the userDef4.
   */
  public String getUserDef4() {
    return(this.userDef4);
  }
  /**
   * @param userDef4 The userDef4 to set.
   */
  public void setUserDef4(String userDef4) {
    this.userDef4 = userDef4;
  }
  /**
   * @return Returns the userDef5.
   */
  public String getUserDef5() {
    return(this.userDef5);
  }
  /**
   * @param userDef5 The userDef5 to set.
   */
  public void setUserDef5(String userDef5) {
    this.userDef5 = userDef5;
  }
  /**
   * @return Returns the workflowStepSource.
   */
  public WorkflowStep getWorkflowStepSource() {
    return(this.workflowStepSource);
  }
  /**
   * @param workflowStepSource The workflowStepSource to set.
   */
  public void setWorkflowStepSource(WorkflowStep workflowStepSource) {
    this.workflowStepSource = workflowStepSource;
  }
  
  /******************************
   * Presentation Functions
   ******************************/
  
  public Integer getWorkflowRecordID() {
    return(this.workflowRecordID);
  }
  /**
   * @param workflowRecordID The workflowRecordID to set.
   */
  public void setWorkflowRecordID(Integer workflowRecordID) {
    this.workflowRecordID = workflowRecordID;
  }
  /**
   * @return Returns the workflowCode.
   */
  public String getWorkflowCode() {
    return(this.workflowCode);
  }
  /**
   * @param workflowCode The workflowCode to set.
   */
  public void setWorkflowCode(String workflowCode) {
    this.workflowCode = workflowCode;
  }
  /**
   * @return Returns the workflowVersion.
   */
  public String getWorkflowVersion() {
    return(this.workflowVersion);
  }
  /**
   * @param workflowVersion The workflowVersion to set.
   */
  public void setWorkflowVersion(String workflowVersion) {
    this.workflowVersion = workflowVersion;
  }
  /**
   * @return Returns the workflowDescription.
   */
  public String getWorkflowDescription() {
    return(this.workflowDescription);
  }
  /**
   * @param workflowDescription The workflowDescription to set.
   */
  public void setWorkflowDescription(String workflowDescription) {
    this.workflowDescription = workflowDescription;
  }
  /**
   * @return Returns the workflowCategory.
   */
  public String getWorkflowCategory() {
    return(this.workflowCategory);
  }
  /**
   * @param workflowCategory The workflowCategory to set.
   */
  public void setWorkflowCategory(String workflowCategory) {
    this.workflowCategory = workflowCategory;
  }
  /**
   * @return Returns the workflowCategoryID.
   */
  public Integer getWorkflowCategoryID() {
    return(this.workflowCategoryID);
  }
  /**
   * @param workflowCategoryID The workflowCategoryID to set.
   */
  public void setWorkflowCategoryID(Integer workflowCategoryID) {
    this.workflowCategoryID = workflowCategoryID;
  }
  /**
   * @return Returns the stepSeq.
   */
  public Integer getStepSeq() {
    return(this.stepSeq);
  }
  /**
   * @param stepSeq The stepSeq to set.
   */
  public void setStepSeq(Integer stepSeq) {
    this.stepSeq = stepSeq;
  }
  /**
   * @return Returns the stepName.
   */
  public String getStepName() {
    return(this.stepName);
  }
  /**
   * @param stepName The stepName to set.
   */
  public void setStepName(String stepName) {
    this.stepName = stepName;
  }
  /**
   * @return Returns the actionType.
   */
  public String getActionType() {
    return(this.actionType);
  }
  /**
   * @param actionType The actionType to set.
   */
  public void setActionType(String actionType) {
    this.actionType = actionType;
  }
  /**
   * @return Returns the stepDescription.
   */
  public String getStepDescription() {
    return(this.stepDescription);
  }
  /**
   * @param stepDescription The stepDescription to set.
   */
  public void setStepDescription(String stepDescription) {
    this.stepDescription = stepDescription;
  }
  /**
   * @return Returns the priority.
   */
  public String getPriority() {
    return(this.priority);
  }
  /**
   * @param priority The priority to set.
   */
  public void setPriority(String priority) {
    this.priority = priority;
  }
  /**
   * @return Returns the allowStop.
   */
  public String getAllowStop() {
    return(this.allowStop);
  }
  /**
   * @param allowStop The allowStop to set.
   */
  public void setAllowStop(String allowStop) {
    if (allowStop != null) {
      this.allowStop = allowStop;
    }
  }
  /**
   * @return Returns the onNoResponseAfter.
   */
  public Timestamp getOnNoResponseAfter() {
    return(this.onNoResponseAfter);
  }
  /**
   * @param onNoResponseAfter The onNoResponseAfter to set.
   */
  public void setOnNoResponseAfter(Timestamp onNoResponseAfter) {
    this.onNoResponseAfter = onNoResponseAfter;
  }
  /**
   * @return Returns the onNoResponseFor.
   */
  public Integer getOnNoResponseFor() {
    return(this.onNoResponseFor);
  }
  /**
   * @param onNoResponseFor The onNoResponseFor to set.
   */
  public void setOnNoResponseFor(Integer onNoResponseFor) {
    this.onNoResponseFor = onNoResponseFor;
  }
  /**
   * @return Returns the startDate.
   */
  public Timestamp getStartDate() {
    return(this.startDate);
  }
  /**
   * @param startDate The startDate to set.
   */
  public void setStartDate(Timestamp startDate) {
    this.startDate = startDate;
  }
  /**
   * @return Returns the endDate.
   */
  public Timestamp getEndDate() {
    return(this.endDate);
  }
  /**
   * @param endDate The endDate to set.
   */
  public void setEndDate(Timestamp endDate) {
    this.endDate = endDate;
  }
  /**
   * @return Returns the userActorList.
   */
  public List getUserActorList() {
    return(this.userActorList);
  }
  /**
   * @param userActorList The userActorList to set.
   */
  public void setUserActorList(List userActorList) {
    this.userActorList = userActorList;
  }
  /**
   * Determines if the task is overdued. It will check for both the onNoResponseAfter
   * and onNoResponseFor properties. If the task is not completed after the due date
   * it will be treated as delayed.
   * 
   * @return True if the task is not completed after due date.
   */
  public boolean isDelay() {
    //if (this.getOnNoResponseAfter()==null && this.getOnNoResponseFor()==null) {//simon_del_for_bug[3976]
    if (this.getDueDate()==null) {//simon_add_for_bug[3976]
      return(false);
    }
    Timestamp currTime = Utility.getCurrentTimestamp();//simon_add_for_bug[3976]
    if (WorkflowProgress.STATUS_PENDING.equals(this.getStatus())) {
      /*simon_del_S_for_bug[3976]
      if (this.getOnNoResponseAfter() != null) {
        if (Utility.getCurrentTimestamp().after(this.getOnNoResponseAfter())) {
          return(true);
        }
      } else if (this.getOnNoResponseFor() != null) {
        java.util.Calendar tmpCal = Utility.timestampToCalendar(this.getCreateDate());
        tmpCal.add(Calendar.DAY_OF_MONTH, this.getOnNoResponseFor().intValue());
        java.sql.Timestamp tmpTime = Utility.calendarToTimestamp(tmpCal);
        if (Utility.getCurrentTimestamp().after(tmpTime)) {
          return(true);
        }
      }*///simon_del_E_for_bug[3976]
      //simon_add_S_for_bug[3976]
      if(currTime.after(this.getDueDate())){
        return(true);
      }
      //simon_add_E_for_bug[3976]
    } else {
      /*simon_del_S_for_bug[3976]
      if (this.getOnNoResponseAfter() != null) {
        if (this.getUpdateDate().after(this.getOnNoResponseAfter())) {
          return(true);
        }
      } else if (this.getOnNoResponseFor() != null) {
        java.util.Calendar tmpCal = Utility.timestampToCalendar(this.getCreateDate());
        tmpCal.add(Calendar.DAY_OF_MONTH, this.getOnNoResponseFor().intValue());
        java.sql.Timestamp tmpTime = Utility.calendarToTimestamp(tmpCal);
        if (this.getUpdateDate().after(tmpTime)) {
          return(true);
        }
      }
      *///simon_del_E_for_bug[3976]
      //simon_add_S_for_bug[3976]
      if(this.getUpdateDate().after(this.getDueDate())){
        return(true);
      }
      //simon_add_E_for_bug[3976]
    }
    return(false);
  }
  /**
   * @return Returns the dueDate.
   */
  public Timestamp getDueDate() {
    if(!Utility.isEmpty(this.dueDate)) {
      return this.dueDate;
    } else if (this.onNoResponseAfter!=null){
      return this.onNoResponseAfter;
    }else if (this.onNoResponseFor!=null){
      Timestamp dueDate = Utility.addDay(this.getCreateDate(),this.getOnNoResponseFor().intValue());
      Calendar tmpDate = Utility.timestampToCalendar(dueDate);
      //Utility.setCalendarTime(tmpDate, 23, 59, 59, 0);
      dueDate = Utility.calendarToTimestamp(tmpDate);
      return dueDate;
    } else{
      return this.dueDate;
    }
    
  }
  /**
   * @param dueDate The dueDate to set.
   */
  public void setDueDate(Timestamp dueDate){
    this.dueDate = dueDate;
  }
  /**
   * @return Returns the allowAssignDueDate.
   */
  public String getAllowAssignDueDate(){
    return this.allowAssignDueDate;
  }
  /**
   * @param allowAssignDueDate The allowAssignDueDate to set.
   */
  public void setAllowAssignDueDate(String allowAssignDueDate){
    this.allowAssignDueDate = allowAssignDueDate;
  }
  /**
   * @return Returns the nextStepDueDate.
   */
  public Timestamp getNextStepDueDate(){
    return this.nextStepDueDate;
  }
  /**
   * @param nextStepDueDate The nextStepDueDate to set.
   */
  public void setNextStepDueDate(Timestamp nextStepDueDate){
    this.nextStepDueDate = nextStepDueDate;
  }
  /**
   * @return Returns the nextStepAllowAssignDueDate.
   */
  public String getNextStepAllowAssignDueDate(){
    return this.nextStepAllowAssignDueDate;
  }
  /**
   * @param nextStepAllowAssignDueDate The nextStepAllowAssignDueDate to set.
   */
  public void setNextStepAllowAssignDueDate(String nextStepAllowAssignDueDate){
    this.nextStepAllowAssignDueDate = nextStepAllowAssignDueDate;
  }
  /**
   * @return Returns the nextStepDueDates.
   */
  public String getNextStepDueDates(){
    return this.nextStepDueDates;
  }
  /**
   * @param nextStepDueDates The nextStepDueDates to set.
   */
  public void setNextStepDueDates(String nextStepDueDates) {
    this.nextStepDueDates = nextStepDueDates;
  }
  /**
   * @return Returns the submitter.
   */
  public String getSubmitter(){
    return this.submitter;
  }
  /**
   * @param submitter The submitter to set.
   */
  public void setSubmitter(String submitter) {
    this.submitter = submitter;
  }
  /**
   * @return Returns the progressPriority.
   */
  public String getProgressPriority(){
    return this.progressPriority;
  }
  /**
   * @param progressPriority The progressPriority to set.
   */
  public void setProgressPriority(String progressPriority){
    this.progressPriority = progressPriority;
  }
  /**
   * @return Returns the priorityRuleListValue.
   */
  public String getPriorityRuleListValue(){
    return this.priorityRuleListValue;
  }
  /**
   * @param priorityRuleListValue The priorityRuleListValue to set.
   */
  public void setPriorityRuleListValue(String priorityRuleListValue) {
    this.priorityRuleListValue = priorityRuleListValue;
  }
  
  public boolean isAssignPriorityRuleNextStep(){
    return this.isAssignPriorityRuleNextStep;
  }
  
  public void setIsAssignPriorityRuleNextStep(boolean isAssignPriorityRuleNextStep){
    this.isAssignPriorityRuleNextStep = isAssignPriorityRuleNextStep;
  }
  
	public String getStageName() {
		return stageName;
	}
	
	public void setStageName(String stageName) {
		this.stageName = stageName;
	}
  
	public List getPickUpUserName() {
		return pickUpUserName;
	}
  
	public void setPickUpUserName(List pickUpUserName) {
		this.pickUpUserName = pickUpUserName;
	}
}

